<?php
include("header.php");
include("model/DB.php");
include("model/User.php");
include("model/Kid.php");
include("model/Daliy.php");
include("model/Class.php");
include("model/Msg.php");
include("function/parent.login.php");

$kid = Kid::getKidByParent($_SESSION['userid']);
$msgs = Msg::getMsgs($_SESSION['userid']);
if(!$_GET['date']){
$date = date("Y-m-d");
}
else{
$date = $_GET['date'];
}
$daliy = Daliy::getDaliy($kid['id'],$date);
$class = Classes::getClassById($kid['class_id']);

$teacher = $class['teacher_id'];
?>
<script>
$(document).ready(function(){
$("#datepicker").datepicker({
	showOn: 'button',
	buttonImage: 'images/calendar.gif',
	buttonImageOnly: true,
	dateFormat: 'yy-mm-dd'
});	

	$("#msg").click(function(){
		if($("#msg_box").is(":hidden")){
			$("#msg_box").slideDown();
		}
		else{
			$('#msg_box').slideUp();
		}
	});
	$(window).scroll(function()
			{
				$('#msg_box').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 350});  
			});
	$('#close_login').click(function()
			{
		  		//the messagebox gets scrool down with top property and gets hidden with zero opacity 
				$('#msg_box').slideUp();
				
			});		
	$("#send_msg").click(function(){
			var msg = $("#msg_content").val();
			var to_id = $("#teacher").val();
			$.post("function/addMsg.php",
				   {msg:msg,to_id:to_id},
				   function(data){
					   if(data=="saved"){
						   alert("Message Has Been Sent");
					   }else{
						   alert(data);
					   }
				   }
					);
		});
});
function change_date(v){
	window.location="parent.php?date="+v;
}

</script>
<div id="login_gif"><a href="logout.php"><img src="images/login.gif" border=0></a></div>
<div id="home_body">
	<center>
	<div id="home_navi">
		<div class="navi_img">
			<a href="index.php"><img src="images/ourclass.gif"  border="0" height="160"></a>
		</div>          
		<div class="navi_img">                 
			<a href="admin.php"><img src="images/ourstudies.gif"  border="0" height="160"></a>
		</div>           
		<div class="navi_img">
			<a href="photo.php"><img src="images/ourschool.gif" border="0" height="160"></a>
		</div>
		<div class="navi_img">
			<a href="parent.php"><img src="images/justforkids.gif" border="0" height="160"></a>
		</div>
		<div class="navi_img">
			<a href="teacher.php"><img src="images/justforparents.gif"  border="0" height="160"></a>
		</div>
	</div>
	<div id="home_content">
		<div id="leftside">
		</div>
		<div id="home_main_content">
			<div id="welcome">
				
				<img src="images/parentscenteredbanner.gif" border="0">
			</div>
			<div id="parent_content">
				<div id="in_parent">
					<div id="in_parent_avatar"><img src="avatar/<?php echo $kid['avatar']; ?>"></div>
					<img src="images/pencil.gif">
					
					<div style="text-align:right;">
						<a id="msg" style="margin-right:30px;font-size:13px;" href="javascript:void(0)">Message<img border="0" src="images/book.png"></a><input type="hidden" value="<?=$teacher?>" id="teacher">
					</div>
					<table  width="400" style="margin-top:10px;text-align:center">
						<tr><td colspan="2"><center><b>Basic Information</b></center></td></tr>
						<tr>
							<td><span class="info_title">Name:</span><span class="info_value"><?php echo $kid['name']; ?></span></td>
							<td><span class="info_title">Class:</span><span class="info_value"><?php echo $kid['title']; ?></span></td>
						</tr>
						<tr>
							<td><span class="info_title">Weight:</span><span class="info_value"><?php echo $kid['weight']; ?> Kg</span></td>
							<td><span class="info_title">Height:</span><span class="info_value"><?php echo $kid['height']; ?> Cm</span></td>
						</tr>
						<tr>
							<td>&nbsp;</td>
						</tr>
						<tr>
							<td colspan="2"><center><b>Daliy Status</b></center></td>
						</tr>
						<tr>
							<td colspan="2"><center><font color="red"><?php echo $date; ?></font> <input type="hidden" id="datepicker" onchange="change_date(this.value)"></center></td>
						</tr>						
						<?php if($daliy){ ?>
						<script>
						jQuery(document).ready(function(){
							
								var content = jQuery("#perform_notice").html();
								
								$("#tooltip_notice").qtip(
								  {
									 content: content,
									 position: {
											corner: {
											   tooltip: 'bottomLeft',
											   target: 'topRight'
											}
										 },
									 style: {
											tip: true, // Give it a speech bubble tip with automatic corner detection
											name: 'cream'
										 }
								
								});		
							
						});	

						</script>

						<tr>
							<td><span class="info_title">Healthy Status:</span><span class="info_value"><?php echo $daliy['status']; ?></span></td>
							<td><span class="info_title">Lunch:</span><span class="info_value"><?php echo $daliy['lunch']; ?></span></td>
						</tr>
						<tr>
							<td><span class="info_title">Siesta:</span><span class="info_value"><?php echo $daliy['siesta']; ?></span></td>
							<td><span class="info_title">Performance:</span><span class="info_value"><a id="tooltip_notice" href="javascript:void(0)" title=""><?php echo $daliy['perform']; ?></a></span><span id="perform_notice" style="display:none" >O:Outstanding<br>E:Exceeds Expectations<br>A:Acceptable<br>P:Poor<br>D:Dreadful<br>T:Troll<br>X:Absent</span></td>
						</tr>
						<?php }else{ ?>
						<tr>
							<td colspan="2"><center>Waiting for evaluate....</center></td>
						</tr>
						<?php } ?>	
									
					</table>
					<div id="msg_box">
							<img id="close_login" style="float:right;cursor:pointer"  src="images/cross.png" />
							<br>
							<center><textarea id="msg_content"></textarea><br><input style="margin-bottom:20px;" id="send_msg" type="button" value="Send"></center>
							<div id="msg_record">
								
								<?php if($msgs):foreach($msgs as $msg): 
								$user = User::getUser('id',$msg['from_id']);
								?>
								
								<div class="msg_each">
									<div class="" style="border-bottom:1px dotted black; width:100%;"><?php if($msg['from_id']==$_SESSION['userid']){ ?>You:<?php }else{ echo $user[0]['username'].":"; } echo $msg['content'];?> <br><span class="msg_date"><?=$msg['datetime']?></span></div>
								</div>
								<?php endforeach; endif; ?>
							</div>
						

					</div>
					
					
				</div>
				
			</div>
			<br>
			<br>
			<img src="images/divider.gif" border="0">
		</div>
		<div id="rightside">
		</div>
	</div>
	</center>
</div>